<template>
  <view class="viewpoint">
    <!-- 个人信息 -->
    <view class="userInfo" :style="{ paddingTop: safeAreaInsets!.top + 'px'}">
      <view class="contain">
        <view class="Info">
          <!-- 用户头像 -->
          <view class="avatar">
            <image :src="detailList.userInfo.avatar" />
          </view>
          <!-- 用户信息 -->
          <view class="Info_item">
            <view class="A"
              ><text>{{ detailList.userInfo.username }}</text></view
            >
            <view class="B"
              ><text>已发布:{{ productnum }}篇</text></view
            >
          </view>
        </view>
        <view class="introduce C">
          <text>{{ detailList.userInfo.userInfo }}</text>
        </view>
        <view class="address C">
          <text v-if="detailList.userInfo.address">IP:{{ detailList.userInfo.address }}</text>
          <text v-else>IP:未填写</text>
          <text v-if="detailList.userInfo.sex" style="margin-left: 10rpx"
            >性别：{{ detailList.userInfo.sex == '0' ? '男' : '女' }}</text
          >
          <text style="margin-left: 10rpx" v-else>性别:未填写</text>
        </view>
      </view>
    </view>
    <view class="tabBar">
      <view :class="index == 0 ? 'works active' : 'works'" @tap="index = 0">作品</view>
    </view>
    <view class="produce">
      <swiper>
        <swiper-item>
          <scroll-view scroll-y>
            <!-- 用户作品 -->
            <view
              class="works"
              @tap="productDetail(items)"
              v-for="items in detailList.news"
              :key="items.newsId"
            >
              <!-- 用户信息 -->
              <view class="user">
                <view class="avatar">
                  <image :src="detailList.userInfo.avatar" />
                </view>
                <view class="userinfo">
                  <view>{{ detailList.userInfo.username }}</view>
                  <view>{{ items.releaseTime }}</view>
                </view>
              </view>
              <!-- 新闻信息 -->
              <view class="news">
                <view class="title">
                  {{ items.title }}
                </view>
                <view class="cover"><image :src="items.newsImgArr[0]" /></view>
                <view class="static P">已上架</view>
              </view>
            </view>
          </scroll-view>
        </swiper-item>
      </swiper>
    </view>
  </view>
  <view> </view>
</template>

<script setup lang="ts">
import { onLoad } from '@dcloudio/uni-app'
import { ref, defineProps } from 'vue'
import { auditorDetailAPI } from '@/services/detail'
import type { auditorDetail } from '@/types/index'
const { safeAreaInsets } = uni.getSystemInfoSync()
const query = defineProps<{ account: string }>()
const detailList = ref<auditorDetail>()
const index = ref(0)
const productnum = ref(0)
const getDetail = async () => {
  const res = await auditorDetailAPI(query.account)
  detailList.value = res.data
  productnum.value = res.data.news.length
}

const productDetail = (items: any) => {
  uni.navigateTo({ url: `/pages/detail/detail?newsId=${items.newsId}` })
}
onLoad(() => {
  getDetail()
})
</script>

<style lang="scss">
page {
  height: 100%;
}
.viewpoint {
  display: flex;
  flex-direction: column;
  height: 100%;
  .userInfo::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url(https://pr1-greenteacdn.lenovo.com.cn/config/1669706061273_05.jpg) no-repeat;
    background-size: 100% 100%;
    filter: blur(4px);
    z-index: -1;
    background-size: cover;
  }
  .userInfo {
    position: relative;
    height: 450rpx;
    width: 100%;

    padding: 0 100rpx;
    .Info {
      height: 120rpx;
      width: 100%;
      display: flex;

      .avatar {
        height: 120rpx;
        width: 120rpx;
        border-radius: 120rpx;
        overflow: hidden;
      }
      .Info_item {
        padding: 10rpx 0;
        margin-left: 20rpx;
        height: 120rpx;
        flex: 1;
        display: flex;
        justify-content: space-around;
        flex-direction: column;
        .A,
        .B {
          color: #fff;
          width: 100%;
        }
        .A {
          font-weight: bold;
        }
        .B {
          font-size: 28rpx;
        }
      }
    }
    .setting {
      top: 60rpx;
      right: 60rpx;
      position: absolute;
      .iconfont {
        font-size: 60rpx;
        color: #fff;
        font-weight: bold;
      }
    }
  }
  .tabBar {
    height: 100rpx;
    width: 100%;
    display: flex;
    justify-content: space-around;
    view {
      height: 100%;
      width: 100%;
      text-align: center;
      line-height: 100rpx;
    }
    .active {
      border-bottom: 10rpx solid #f04142;
    }
  }
  .produce {
    background-color: #f2ecec;
    flex: 1;
    width: 100%;
    padding: 0 20rpx;
    .empty_swiper {
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      height: 100%;
      width: 100%;
      .defaulimg_swiper {
        margin-bottom: 30rpx;
        width: 120rpx;
        height: 120rpx;
        border-radius: 100rpx;
        overflow: hidden;
      }
      .unlogin_swiper {
        width: 130rpx;
        height: 50rpx;
        font-size: 28rpx;
        background-color: #b1afaf;
        color: #fff;
        border-radius: 10rpx;
        text-align: center;
        line-height: 50rpx;
        font-weight: bold;
      }
    }
    .works {
      width: 100%;
      height: 290rpx;
      background-color: #fff;
      padding: 15rpx 15rpx 15rpx 15rpx;
      border-radius: 10rpx;
      margin-top: 10rpx;
      text-align: left;
      .user {
        width: 100%;
        height: 80rpx;
        display: flex;

        .avatar {
          height: 100%;
          width: 80rpx;
          border-radius: 80rpx;
          overflow: hidden;
        }
        .userinfo {
          height: 100%;
          flex: 1;
          display: flex;
          justify-content: space-between;
          line-height: 80rpx;
          font-size: 28rpx;
          margin-left: 10rpx;
        }
      }
      .news {
        width: 100%;
        height: 180rpx;
        display: flex;
        position: relative;
        .static {
          position: absolute;
          left: 10rpx;
          bottom: 5rpx;
          font-size: 24rpx;
          height: 40rpx;
          width: 100rpx;
          text-align: center;
          line-height: 40rpx;

          color: #fff;
        }
        .P {
          background-color: #42cb42;
        }
        .D {
          background-color: rgb(197, 197, 4);
        }
        .title {
          font-weight: bold;
          height: 90rpx;
          flex: 1;
          margin-top: 10rpx;
          padding: 10rpx 20rpx;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          line-clamp: 2;
          -webkit-box-orient: vertical;
        }
        .cover {
          height: 100%;
          width: 180rpx;
        }
      }
    }
  }
}
.contain {
  position: absolute;
  top: 120rpx;
  .profile {
    margin-top: 20rpx;
    font-size: 28rpx;
  }
  .C {
    color: #f2d7d7;
  }
  .introduce {
    margin-top: 20rpx;
    font-size: 28rpx;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    line-clamp: 1;
    -webkit-box-orient: vertical;
  }
  .address {
    margin-top: 10rpx;
    font-size: 28rpx;
  }
}
.empty {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  height: 100%;
  width: 100%;
  .defaulimg {
    margin-bottom: 30rpx;
    width: 120rpx;
    height: 120rpx;
    border-radius: 100rpx;
    overflow: hidden;
  }
  .unlogin {
    width: 120rpx;
    height: 50rpx;
    font-size: 28rpx;
    background-color: #f04142;
    color: #fff;
    border-radius: 10rpx;
    text-align: center;
    line-height: 50rpx;
    font-weight: bold;
  }
}
.iconfont {
  font-size: 28rpx;
}
.setting_select {
  width: 400rpx;
  .setting_contain {
    margin: 0 20rpx 20rpx 20rpx;
    border-bottom: 1rpx solid #ccc;
  }
}
.Q {
  width: 100%;
  height: 100rpx;
  text-align: left;
  margin-left: 20rpx;
  line-height: 100rpx;
  .iconfont {
    font-size: 40rpx;
    margin-right: 30rpx;
    font-weight: bold;
  }
  .selection {
    font-size: 32rpx;
  }
}
</style>